﻿using fabao.Common.Entity;
//using ICSharpCode.SharpZipLib.Zip;
using System;
using System.Collections.Generic;
using System.IO.Compression;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace fabao.Common.Util
{
    public class ZipHelper
    {
        /// <summary>
        /// 根据文件路径批量压缩
        /// </summary>
        /// <param name="fileNames"></param>
        /// <param name="compresssionLevel"></param>
        /// <param name="saveFullPath"></param>
        /// <param name="password"></param>
        /// <param name="comment"></param>
        //public static Stream FilesZip(List<ZipStreamModel> streams, int? compresssionLevel, string password = "", string comment = "")
        //{
        //    Stream saveStream = new MemoryStream();
        //    ZipOutputStream zos = new ZipOutputStream(saveStream);
        //    if (compresssionLevel.HasValue)
        //    {
        //        zos.SetLevel(compresssionLevel.Value);//设置压缩级别
        //    }

        //    if (!string.IsNullOrEmpty(password))
        //    {
        //        zos.Password = password;//设置zip包加密密码
        //    }

        //    if (!string.IsNullOrEmpty(comment))
        //    {
        //        zos.SetComment(comment);//设置zip包的注释
        //    }

        //    foreach (var onemodel in streams)
        //    {
        //        Stream fs = onemodel.stream;
        //        fs.Position = 0;
        //        byte[] buffer = new byte[fs.Length];
        //        fs.Read(buffer, 0, buffer.Length);
        //        ZipEntry entry = new ZipEntry(onemodel.fileName);
        //        zos.PutNextEntry(entry);
        //        zos.Write(buffer, 0, buffer.Length);
        //        zos.CloseEntry();
        //        fs.Close();
        //    }
        //    zos.IsStreamOwner = false;
        //    zos.Finish();
        //    zos.Close();
        //    saveStream.Position = 0;
        //    return saveStream;
        //}
    }
}
